package com.huahua.api.controller.utility;

import com.huahua.api.entity.base.R;
import com.huahua.api.entity.param.QrCodeGenerateParam;
import com.huahua.api.service.utility.QrCodeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

/**
 * 二维码生成控制器
 *
 * @author Huahua-Ai
 * @date 2025-08-23 15:40:00
 */
@Slf4j
@RestController
@RequestMapping("/utility/qrcode")
@RequiredArgsConstructor
@CrossOrigin
public class QrCodeController {

    private final QrCodeService qrCodeService;

    /**
     * 生成二维码
     *
     * @param param 二维码生成参数
     * @return 二维码OSS地址
     */
    @PostMapping("/generate")
    public Mono<R<String>> generateQrCode(@RequestBody QrCodeGenerateParam param) {
        return qrCodeService.generateQrCode(param)
                .map(R::success)
                .doOnError(e -> log.error("生成二维码失败", e))
                .onErrorResume(e -> Mono.just(R.error(e.getMessage())));
    }
}
